import { defineStore } from 'pinia'
import api from '@/api/api'

export const useAuthStore = defineStore('auth', {
  state: () => ({
    user: JSON.parse(localStorage.getItem('hhndlxhflowers')),
    isLoggedIn: null,
    loginMessage:'',
    sysInfo:{},
    shopingCarList:[]
  }),

  actions: {
    login(userAccount, userToken, userLogin) {// 模拟登录请求
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          let verForm = {userAccount, userToken, userLogin}
          api.post('/fontdesk/verLogin.php',verForm,{headers:{'Content-Type':'multipart/form-data'}})
          .then((res)=>{
            this.isLoggedIn = res.data.data;return true;
          }).catch(()=>{
            this.isLoggedIn = false;return true;
          })
        },0)
      })
    },
    logout() {
      this.user = null
      this.isLoggedIn = false
    },
  },
})